package com.st.chapter01;

import java.math.BigDecimal;
import java.util.Scanner;

import org.junit.Test;

public class Test2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入一个年份：");
		int num1 = sc.nextInt();
		if ((num1 % 4 == 0 && num1 % 100 != 0) || (num1 % 400 == 0)) {
			System.out.println(num1 + "是闰年");
		} else {
			System.out.println("不是闰年");
		}

	}

	@Test
//	编写一个收银台收款程序，if
//	定义输入----单价、数量、金额
//	定义输出----应收金额、找零
//	使用double类型变量 scanner.nextDouble();
//	2.2、当总价>=500时候打八折
//	2.3、考虑程序出现异常的情况，如：收款金额小于应收金额
//	      若收款金额大于等于应收金额，则计算找零后输出
//	      若收款金额小于应收金额，输出错误信息。
	public void test3() {
		Scanner sc = new Scanner(System.in);
		System.out.println("请分别输入单价，数量，金额");
		double price = sc.nextDouble();
		double amount = sc.nextDouble();
		double money = sc.nextDouble();// 收款金额
		double receviableMoney = 0;// 应收金额
		double totalPrice = mul(price, amount);// 商品总价钱

		if (totalPrice < 500) {
			receviableMoney = totalPrice;
			if (money < receviableMoney) {
				System.out.println("错误信息");
				return;
			} else {

				double change = sub(money, receviableMoney);// 找零
				System.out.println("应收金额:" + receviableMoney + "找零" + change);
			}
		} else {
			receviableMoney = totalPrice * 0.8;
			if (money < receviableMoney) {
				System.out.println("错误信息");
				return;
			} else {

				double change = sub(money, receviableMoney);// 找零
				System.out.println("应收金额:" + receviableMoney + "找零" + change);
			}
		}

	}

	private static final int DEF_DIV_SCALE = 3;
 
	// 相加
	public static double add(double d1, double d2) {
		BigDecimal b1 = new BigDecimal(Double.toString(d1));
		BigDecimal b2 = new BigDecimal(Double.toString(d2));
		return b1.add(b2).doubleValue();

	}

	// 相减
	public static double sub(double d1, double d2) {
		BigDecimal b1 = new BigDecimal(Double.toString(d1));
		BigDecimal b2 = new BigDecimal(Double.toString(d2));
		return b1.subtract(b2).doubleValue();

	}

	// 相乘
	public static double mul(double d1, double d2) {
		BigDecimal b1 = new BigDecimal(Double.toString(d1));
		BigDecimal b2 = new BigDecimal(Double.toString(d2));
		return b1.multiply(b2).doubleValue();

	}

	// 相除
	public static double div(double d1, double d2, int scal) {

		return div(d1, d2, DEF_DIV_SCALE);

	}

	@Test
	public void test4() {
		Scanner sc = new Scanner(System.in);
		int num1 = sc.nextInt();
		int num2 = sc.nextInt();
		System.out.println(num1 + "," + num2);
		int temp;
		temp = num1;
		num1 = num2;
		num2 = temp;
		System.out.println(num1 + "," + num2);

	}
}
